<template>
  <div :class="{toast:true,current:isshow}" @click.stop>
    <div class="toast-arrow"></div>
    <div class="toast-content">
      <div class="all-cate" v-if="cate.all">
        <span @click="cateClick('全部')">{{cate.all.name}}</span>
      </div>
      <table>
        <tr v-for="(item,index) of category" :key="index">
          <td>{{item}}</td>
          <td :class="{last: index === category.length-1}">
            <span v-for="cat in catedetail[index]" :key="cat.index" class="name">
              <span @click="cateClick(cat.name)" :class="{active: catitem === cat.name}">{{cat.name}}</span>
              <span>|</span>
            </span>
          </td>
        </tr>
      </table>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    isshow: {
      type: Boolean,
      default: true
    },
    cate: {
      type: Object,
      default() {
        return {}
      }
    },
    category: {
      type: Array,
      default() {
        return []
      }
    },
    catedetail: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      catitem: null
    }
  },
  methods: {
    // 选择歌单分类
    cateClick(category) {
      this.catitem = category
      this.$emit('cateClick', category)
    }
  }
}
</script>

<style scoped>
/* 弹出框 */
.toast {
  position: absolute;
  z-index: 999;
  top: 85px;
}
.toast-arrow {
  position: absolute;
  z-index: 999;
  top: -10px;
  left: 150px;
  width: 25px;
  height: 11px;
  background: url(~@/assets/img/iconall.png) -48px 0;
}

/* 弹出框内容 */
.toast-content {
  position: absolute;
  width: 600px;
  font-size: 12px;
  background-color: #fff;
  border-radius: 8px;
}

/* 全部分类 */
.all-cate {
  height: 50px;
  line-height: 50px;
  padding-left: 30px;
  border-bottom: 1px solid #ccc;
}
.all-cate span {
  padding: 5px 10px;
  border-radius: 5px;
  border: 1px solid #ccc;
  cursor: pointer;
}

/* 详细分类 */
table {
  border-collapse: collapse;
  color: #333;
}
tr {
  line-height: 25px;
}
tr td:nth-child(1) {
  width: 100px;
  padding-top: 20px;
  font-weight: 700;
  text-align: center;
  vertical-align: top;
  border-right: 1px solid #ccc;
}
tr td:nth-child(2) {
  padding: 20px 10px 0 20px;
}

.last {
  padding-bottom: 20px !important;
}

/* 右半边文字 */
.name span {
  white-space: nowrap;
}
.name span:nth-child(1) {
  cursor: pointer;
  padding: 2px 5px;
}
.name span:nth-child(1):hover {
  text-decoration: underline;
}
.name span:nth-child(2) {
  padding: 0 8px;
  color: #ccc;
}

.active {
  background-color: #a7a7a7;
  color: #fff;
}
/* 隐藏toast */
.current {
  display: none;
}
</style>